
Imports System.Windows.Forms
Public Class clsSupport
#Region "Basic"
    Public Shared Function GetWordCount(ByVal cString As String, ByVal cDelimiter As Char) As Object
        Dim num As Integer = 0
        Dim length As Long = cString.Length
        Dim num3 As Long = 0
        If (cString.Chars(0) <> cDelimiter) Then
            num3 = (num3 + 1)
        End If
        Dim num4 As Integer = (num + 1)
        Dim num5 As Integer = CInt((length - 1))
        num = 0
        Do While (((num4 >> &H1F) Xor num) <= ((num4 >> &H1F) Xor num5))
            If (cString.Chars(num) = cDelimiter) Then
                Do
                    num += 1
                    If (num >= length) Then
                        Exit Do
                    End If
                    If (cString.Chars(num) <> cDelimiter) Then
                        num3 = (num3 + 1)
                        Exit Do
                    End If
                Loop While (1 <> 0)
            End If
            num = (num + num4)
        Loop
        Return num3
    End Function

    Public Shared Function GetWordNum(ByVal cString As String, ByVal nWordPosition As Integer, ByVal cDelimiter As Char) As String
        cString = cString.Trim + cDelimiter
        Dim num As Integer = At(cDelimiter, cString, (nWordPosition - 1))
        Dim num2 As Integer = At(cDelimiter, cString, nWordPosition)
        Return Strings.Mid(cString, (num + 1), ((num2 - 1) - num))
    End Function
    Public Shared Function At(ByVal cSearchFor As String, ByVal cSearchIn As String, ByVal nOccurence As Integer) As Integer
        Return _At(cSearchFor, cSearchIn, nOccurence, 1)
    End Function
    Private Shared Function _At(ByVal cSearchFor As String, ByVal cSearchIn As String, ByVal nOccurence As Integer, ByVal nMode As Integer) As Integer
        Dim num2 As Integer = 0
        Dim num3 As Integer = 0
        Dim startIndex As Integer = 0
        If (nMode = 1) Then
            startIndex = 0
        Else
            startIndex = cSearchIn.Length
        End If
        Dim num5 As Integer = (num2 + 1)
        Dim num6 As Integer = nOccurence
        num2 = 1
        Do While (((num5 >> &H1F) Xor num2) <= ((num5 >> &H1F) Xor num6))
            If (nMode = 1) Then
                startIndex = cSearchIn.IndexOf(cSearchFor, startIndex)
            Else
                startIndex = cSearchIn.LastIndexOf(cSearchFor, startIndex)
            End If
            If (startIndex < 0) Then
                Exit Do
            End If
            num3 += 1
            If (num3 = nOccurence) Then
                Return (startIndex + 1)
            End If
            If (nMode = 1) Then
                startIndex += 1
            Else
                startIndex -= 1
            End If
            num2 = (num2 + num5)
        Loop
        Return 0
    End Function
#End Region
#Region "Sub"
    Public Shared Sub SetValue4Control(ByVal pControl As Control, ByVal Dr As DataRowView, ByVal cAction As String)
        Dim iControl As Control, cFieldName, cSPField As String
        For Each iControl In pControl.Controls
            If Len(iControl.Name) < 4 Then GoTo _Next
            cFieldName = Mid(iControl.Name, 4)

            If InStr(iControl.Tag, "FL") > 0 Then
                CType(iControl, Object).Checked = False
                If Not Dr Is Nothing Then If Dr.DataView.Table.Columns.IndexOf(cFieldName) < 0 Then GoTo _Next
                If cAction = "New" Then
                    If Not Dr Is Nothing Then
                        If InStr(iControl.Tag, "DF") > 0 Then
                            If Not IsDBNull(Dr(cFieldName)) Then
                                CType(iControl, Object).Checked = Dr(cFieldName)
                            Else
                                CType(iControl, Object).Checked = False
                            End If
                        End If
                    End If
                Else
                    If Not IsDBNull(Dr(cFieldName)) Then
                        CType(iControl, Object).Checked = Dr(cFieldName)
                    Else
                        CType(iControl, Object).Checked = False
                    End If
                End If
                GoTo _Next
            End If

            If InStr(iControl.Tag, "RF") > 0 Then
                iControl.Text = ""
                If Not Dr Is Nothing Then If Dr.DataView.Table.Columns.IndexOf(cFieldName) < 0 Then GoTo _Next
                cSPField = cFieldName

                If cAction = "New" Then
                    If Not Dr Is Nothing Then
                        If InStr(iControl.Tag, "DF") > 0 Then
                            If Not IsDBNull(Dr(cSPField)) Then
                                iControl.Text = RTrim(Dr(cSPField))
                            End If
                        End If
                    End If
                Else
                    If Not IsDBNull(Dr(cSPField)) Then
                        iControl.Text = RTrim(Dr(cSPField))
                    End If
                End If
                GoTo _Next
            End If

            If InStr(iControl.Tag, "FC") > 0 Or InStr(iControl.Tag, "FT") > 0 Then
                iControl.Text = ""
                If Not Dr Is Nothing Then If Dr.DataView.Table.Columns.IndexOf(cFieldName) < 0 Then GoTo _Next
                If cAction = "New" Then
                    If Not Dr Is Nothing Then
                        If InStr(iControl.Tag, "DF") > 0 Then
                            If Not IsDBNull(Dr(cFieldName)) Then
                                iControl.Text = RTrim(Dr(cFieldName))
                            End If
                        End If
                    End If
                Else
                    If Not IsDBNull(Dr(cFieldName)) Then
                        iControl.Text = RTrim(Dr(cFieldName))
                    End If
                End If
                GoTo _Next
            End If
_Next:
        Next
    End Sub

    Public Shared Sub GetValueFromControl(ByVal pControl As Control, ByVal Dr As DataRowView)
        Dim iControl As Control, cFieldName, cSPField As String
        With Dr
            For Each iControl In pControl.Controls
                If Len(iControl.Name) < 4 Then GoTo _Next
                cFieldName = Mid(iControl.Name, 4)
                If Dr.DataView.Table.Columns.IndexOf(cFieldName) < 0 Then GoTo _Next

                If InStr(iControl.Tag, "FL") > 0 Then
                    .Item(cFieldName) = CType(iControl, Object).Checked
                    GoTo _Next
                End If

                If InStr(iControl.Tag, "RF") > 0 Then
                    cSPField = cFieldName
                    .Item(cSPField) = iControl.Text
                    GoTo _Next
                End If

                If InStr(iControl.Tag, "FC") > 0 Or InStr(iControl.Tag, "FT") > 0 Then
                    .Item(cFieldName) = iControl.Text
                    GoTo _Next
                End If               
_Next:
            Next
        End With
    End Sub

    Public Shared Sub SetFilterTo(ByVal tcFilterExpression As String, ByVal toView As DataView)
        toView.RowFilter = tcFilterExpression
    End Sub
#End Region
End Class
